package com.wms.wms.service;

import com.wms.wms.entity.InStock;
import com.wms.wms.entity.OutStock;
import com.wms.wms.entity.Product;
import com.wms.wms.mapper.InStockMapper;
import com.wms.wms.mapper.product.ProductMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

@Service
public class InStockService {
    @Autowired
    InStockMapper inStockMapper;
    @Autowired
    ProductMapper productMapper;

    public int totalProductionByParam(String id, Date b, Date e)
    {
        if(id.compareTo("000000") != 0) {
            return inStockMapper.queryProductionByParam(id, b, e);
        }
        else
            return inStockMapper.queryProductionByDate(b,e);
    }
    public int totalProductionByType(String typeId, Date b, Date e)
    {
        List<Product> idList = productMapper.queryIdByType(typeId);
        int count = 0;
        for(Product id:idList){
            count += inStockMapper.queryProductionByParam(id.getId(),b,e);
        }
        return count;
    }

    public ArrayList<InStock> queryByIdAndDate(String id, Date bDate, Date eDate){
        return inStockMapper.queryByIdAndDate(id,bDate,eDate);
    }

    public ArrayList<InStock> queryByDate(String id, Date bDate, Date eDate){
        return inStockMapper.queryByDate(id,bDate,eDate);
    }

    public ArrayList<InStock> queryByTypeAndDate(String id, Date bDate, Date eDate){
        List<Product> idList = productMapper.queryIdByType(id);
        ArrayList<InStock> inStockList = new ArrayList<>();
        for(Product i:idList){
            inStockList.addAll(inStockMapper.queryByIdAndDate(i.getId(),bDate,eDate));
        }
        return inStockList;
    }
}
